#coding=utf-8
import numpy as np
import cv2

lower_blue = np.array([0,0,0])
upper_blue = np.array([170,255,46])
cap = cv2.VideoCapture(0)

while(True):
	ret, frame = cap.read()
	cv2.imshow('frame',frame)
	gray  = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
	canny = cv2.Canny(gray, 30, 150)
	cv2.imshow("canny",canny )
	contours, hierarchy = cv2.findContours(
										canny,
										cv2.RETR_TREE,
										cv2.CHAIN_APPROX_NONE)
	#寻找轮廓
	print "len(contours):",len(contours)
	F = []
	# cv2.drawContours(thresh1, contours, 3, (0,255,0), 3)
	for i in range(len(contours)):
		if cv2.contourArea(contours[i]) > 1500:
			print "Area",cv2.contourArea(contours[i])
			# print "data",contours[i]
			F.append(contours[i])
			# else:
				# contours.erase(i)
	cv2.drawContours(gray, F, -1, (0,255,0), 3)
	print "canny.type",type(canny)
	print "gray.type",type(gray)
	cv2.imshow("thresh",gray )
	
	
	if cv2.waitKey(1) & 0xFF == ord('q'):
		break
cap.release()
cv2.destroyAllWindows()
